//
//  LXMoreAuthorTableVC.m
//  喜马拉雅改良版框架
//
//  Created by liuxin on 15/12/28.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "LXMoreAuthorTableVC.h"

@interface LXMoreAuthorTableVC ()
@property(nonatomic,strong)NSMutableArray *allArray;
@end

@implementation LXMoreAuthorTableVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.allArray  = [NSMutableArray array];
    [self getData];
    [self createNavigation];
    [self createTableView];
}
-(void)createNavigation{
    self.navigationItem.title = self.Title;
    UIImage *left = [UIImage imageNamed:@"icon_back_h@2x.png"];
    left = [left imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:left  style:UIBarButtonItemStyleDone target:self action:@selector(leftAction)];
}
-(void)leftAction{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)createTableView{
    [self.tableView registerClass:[LXMoreAuthorCell class] forCellReuseIdentifier:@"cell"];
}
-(void)getData{
    NSString *StrUrl = @"";
    if ([self.category_name isEqualToString:@"new"]) {
        StrUrl = @"http://mobile.ximalaya.com/m/explore_user_list?category_name=all&condition=new&device=android&page=1&per_page=20";
    }else{
    StrUrl = [NSString stringWithFormat:@"http://mobile.ximalaya.com/m/explore_user_list?category_name=%@&condition=hot&device=android&page=1&per_page=20",self.category_name];
    }
    [AFNetworkTool getUrl:StrUrl body:nil result:HXJSON headerFile:nil success:^(id result) {
        NSArray *array = result[@"list"];
        for (NSDictionary *dic in array) {
            LXMoreAuthorModel *temp = [LXMoreAuthorModel new];
            [temp setValuesForKeysWithDictionary:dic];
            [self.allArray addObject:temp];
        }
        [self.tableView reloadData];
    } failure:^(NSError *error) {
        
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _allArray.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 80;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    LXAuthorTableVC *detail = [LXAuthorTableVC new];
    LXMoreAuthorModel *album =  [_allArray objectAtIndex:indexPath.row];
    detail.Uid = [NSString stringWithFormat:@"%ld",album.uid];
    [self.navigationController pushViewController:detail animated:YES];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    LXMoreAuthorCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.cellModel = [_allArray objectAtIndex:indexPath.row];
    return cell;
}

@end
